<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.math.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.io.UnsupportedEncodingException"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.awt.*"%>
<%@ page import="java.math.*"%>
<%@ page import="java.awt.image.BufferedImage"%>
<%@ page import="com.sun.image.codec.jpeg.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.crypto.BadPaddingException"%>
<%@ page import="javax.crypto.Cipher"%>
<%@ page import="javax.crypto.IllegalBlockSizeException"%>
<%@ page import="javax.crypto.NoSuchPaddingException"%>
<%@ page import="java.io.UnsupportedEncodingException"%>
<%@ page import="java.math.BigInteger"%>
<%@ page import="java.security.InvalidKeyException"%>
<%@ page import="java.security.KeyFactory"%>
<%@ page import="java.security.MessageDigest"%>
<%@ page import="java.security.NoSuchAlgorithmException"%>
<%@ page import="java.security.interfaces.RSAPrivateKey"%>
<%@ page import="java.security.interfaces.RSAPublicKey"%>
<%@ page import="java.security.spec.InvalidKeySpecException"%>
<%@ page import="java.security.spec.PKCS8EncodedKeySpec"%>
<%@ page import="java.security.spec.X509EncodedKeySpec"%>
<%@ page import="java.util.Date" %>
<%@ page import="org.apache.commons.codec.binary.Base64"%>
<%!
	//H把一“.” 开头的字符串，前面加一个零
	public String put0(String str1){
		if(str1.indexOf(".")==0)
			return "0"+str1;
		else
			return str1;
	}

	//前面加零方法，去空方法，传值必须是String
	public String Z_isnull(String zhi){
		zhi=zhi==null?"":zhi;
		if(zhi.length()>0){
			if(zhi.substring(0,1).equals(".")) zhi="0"+zhi;
		}
		return zhi;
	}

	////通用函数
	//public String getName(String sql,Statement stmt) throws Exception{
	//String name="";
	//ResultSet rs=stmt.executeQuery(sql);
	//if(rs.next()){
	//name=rs.getString(1);
	//}rs.close();
	//return name;
//}
	//张培颖 2009-01-13 功能：字符串截断指定长度
	public String truncateString(String source,int len){
		if(source.length()>len){
			return source.substring(0,len)+"...";
		}else{
			return source;
		}
	}
	//张培颖 2009-01-13 功能：字符集转换 ISO-->GBK
	public String ISO2GB(String strFrom) throws UnsupportedEncodingException {
		if (strFrom == null) return null;
		byte byTemp[] = strFrom.getBytes("ISO8859_1");
		String strTo = new String(byTemp, "GBK");
		return strTo.trim();

	}
	public String ISO2UTF8(String strFrom) throws UnsupportedEncodingException {
		if (strFrom == null) return null;
		byte byTemp[] = strFrom.getBytes("ISO8859_1");
		String strTo = new String(byTemp, "UTF-8");
		return strTo.trim();

	}
	public String GB2ISO(String strFrom) throws UnsupportedEncodingException{
		if(strFrom==null)
			return null;
		byte byTemp[]=strFrom.getBytes("GBK");
		String strTo=new String(byTemp,"ISO8859_1");
		return strTo.trim();
	}

	public  static   String decrypt(String str) throws Exception{
		String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIu2BU1JM3ZhVDXl\r\n" +
				"DHOKJGkBBEakVrck/PRJNQXnT+kI1N+zfa6/94+v77MMcM16BhKiG5Rdm2f+Fhqo\r\n" +
				"DgLFmAfNq5vBADAFiQ3jm4EOhFXcO+2EwNzooeeo9l2ks6bXrQFNCTvCSdiRHvE+\r\n" +
				"USj8XbpkPfR/pQtwuhC9GPMJfmpBAgMBAAECgYAGbQknZIjdFrLvMP7L8vxOZsE8\r\n" +
				"l+Mef1wHHGA3n6EESzyx9qkpjXjPKhIbU899vpwNkAPhZMDOHVivly/gdBgpn38X\r\n" +
				"jEorTsvCZlwK0WTUN4AssqL5iFJXRmQrL2QNkwuXYNN1Ix0mgYngGyUSdnfHEQs8\r\n" +
				"Vq1HELSL1OL4ReJmRQJBAKUi8YGpY/f8KphS7gdlQOsF//AonOikJk2QQTbpGi/R\r\n" +
				"lIsGMt5KsOWFxEAMYWq+opcMxrCce8RMf8Pr6MAnQr8CQQDYlae5Sm6M9txgZJXZ\r\n" +
				"mhcJlHbBJyPy3dQXlsg/FtE9kgLuVGYB86MYsqfo9wwsOdBdQpz8gJX1qyZaPJjA\r\n" +
				"LpL/AkA3iksjyu7+hudkl+/KuPlekoQEKASuEhd32t60My5Fiv2kzI7rSL+6UoUw\r\n" +
				"7XkOR9Ozbe6dk+Pkn74RDRUZG5tNAkBw1odrobu29WYbUkw/8mfONeso9ptkDO5S\r\n" +
				"29u4AstAqLGeOZprqeNvGqUgWpWc9QH5lJr1coiuVVzF5owulBVBAkEAhy+fXWhp\r\n" +
				"iV1hGEalwLnAFiquQgUMX9J3ZIcQkwAXHnwW04D5GVAa/v2zvcfWiSQYdO4vFKa3\r\n" +
				"NR6AQC5P7j0s+w==";
		//64位解码加密后的字符串
		byte[] inputByte = Base64.decodeBase64(str.getBytes("UTF-8"));

		//base64编码的私钥
		byte[] decoded = Base64.decodeBase64(privateKey);
		RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));
		//RSA解密
		Cipher cipher = Cipher.getInstance("RSA");
		cipher.init(Cipher.DECRYPT_MODE, priKey);
		String outStr = new String(cipher.doFinal(inputByte));
		return outStr;
	}

	/**
	 * 我方用的加密,刘寿福2019-07-09
	 * @param str
	 * @return
	 */

	public  static   String encryption(String str){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		str=str+"|"+formatter.format(new Date());

		String publicKey="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCL4ZusQzQNvyca+JpVXNMBKFBRKGg0sqqtjxOxqGnwTvvWRKGE/nigOWsBdmjLkpgFrHGwjtwe0Gb5/Z2NlttXGpeWVGADRqxMwcsia+48uuSCn402EjtNEmeEbCVyiK3Pdh7KYop+piW/2BrpoUzn2dbRdGbC5lijrgDAQUXsyQIDAQAB";

		//base64编码的公钥
		byte[] decoded = Base64.decodeBase64(publicKey);
		RSAPublicKey pubKey;
		String outStr="";
		try {
			pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
			//RSA加密
			Cipher cipher = Cipher.getInstance("RSA");
			cipher.init(Cipher.ENCRYPT_MODE, pubKey);
			outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8")));
			return outStr.replace("+", "|A|");
		} catch (InvalidKeySpecException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchPaddingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidKeyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalBlockSizeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BadPaddingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return outStr;

	}
	/**
	 * 我方用的解密
	 * @param str
	 * @return
	 */
	public  static   String decrypt2(String str){

		str = str.replace("|A|", "+");
		String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIvhm6xDNA2/Jxr4mlVc0wEoUFEoaDSyqq2PE7GoafBO+9ZEoYT+eKA5awF2aMuSmAWscbCO3B7QZvn9nY2W21cal5ZUYANGrEzByyJr7jy65IKfjTYSO00SZ4RsJXKIrc92Hspiin6mJb/YGumhTOfZ1tF0ZsLmWKOuAMBBRezJAgMBAAECgYBE0atYNfv/I2Nm5pZvluqM8DuLojiabKiCGRlUV4o/W2yVP1DD8LqCAZ2+q3Xlaer3J58LgU2Ur21qYrdH+MdSOWGR06rE+hhUr0T75QY9AAbE5nr/SvCJ+DNge2mOkla1BledEKBEbQoIhwIcbwWqkK3XjXDhxgUpe7ftQs6pgQJBAM8gLetfBTaG2TWM6h0myVaRua43/HY1ourquCGb3EiiZVgpK1ReT81jFqMDy7lF2jidLkhPD5IlcKj8TdyGb7ECQQCs42bwf4nPmhpxk4HKJzYccnDt1xrFqs+x/ClQf/bQUJcecE91OCvqHvKYAYyPnjyK83bj5rwQOIHITp6o1uyZAkBzqAFcI8PybZwORfBYdNcKSvcG7GZBz7N4P7avtatst5mlf9+dDci75C+4uR7iBrpS0JoOcG8+aT+ebLxBfqQRAkByjxRM1BXbLD/NdnKQIz9lxicyUlB5HmAVjgNKRiCjlGMuVjkwcRIYRn11X8FmAPIZGI51IRUIoojM09uqARAxAkBd9+k/71BnyvxHKlk5UnAhYba+TYMKXW5w+lyFKd7DK0PZ2cxGd7IOcwhMNVd/2QhjLRt8vwf5iEhOvC55f95W";

		//64位解码加密后的字符串
		byte[] inputByte;
		String outStr ="";
		try {
			inputByte = Base64.decodeBase64(str.getBytes("UTF-8"));
			//base64编码的私钥
			byte[] decoded = Base64.decodeBase64(privateKey);
			RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));
			//RSA解密
			Cipher cipher = Cipher.getInstance("RSA");
			cipher.init(Cipher.DECRYPT_MODE, priKey);
			outStr = new String(cipher.doFinal(inputByte));

		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidKeySpecException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchPaddingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidKeyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalBlockSizeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BadPaddingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return outStr;



	}


	public String GB2UTF(String strFrom) throws UnsupportedEncodingException{
		if(strFrom==null)
			return null;
		byte byTemp[]=strFrom.getBytes("GBK");
		String strTo=new String(byTemp,"UTF-8");
		return strTo.trim();
	}
	//长庆油田特殊处理已在server.xlm中增加 URIEncoding="GBK"
	public String ISO2GB_CQ(String strFrom) throws UnsupportedEncodingException {
		if (strFrom == null) return null;
		return strFrom.trim();
	}

	//张培颖 2009-01-13 功能：字符集转换 GBK-->ISO
	public String convertTo8859(String strInput) {
		try {
			String tempStr = strInput;
			byte[] tempStrBytes = tempStr.getBytes("ISO8859-1");
			String strOutput = new String(tempStrBytes);
			return strOutput;
		} catch (Exception e) {
			return "";
		}
	}
	//刘寿福，2009-1-13 功能：分页显示调用。
	public String iiff(boolean condition,String str1,String str2) {
		if (condition)
			return str1;
		else
			return str2;
	}

	//刘寿福，2009-01-14，功能：把日期d按指定格式strFmt格式化成一个字符串返回
	public String GetFmtDate(java.util.Date d ,String strFmt){
		//java.util.Date d1=new java.util.Date();
		if(d==null)
			return "";
		java.text.SimpleDateFormat fmt=new java.text.SimpleDateFormat(strFmt);
		return fmt.format(d);
	}

	//刘寿福，2009-01-14，功能：调用上面的GetFmtDate()函数
	public String Get10Date(java.util.Date thedate){
		return GetFmtDate(thedate,"yyyy-MM-dd");
	}


	//王茁 2009-1-14,功能：字符串替换函数，把原字符串strSource中的strFrom全部替换成strTo
	public static String replace(String strSource, String strFrom, String strTo)  {
		if(strFrom == null || strFrom.equals(""))
			return strSource;
		String strDest = "";
		int intFromLen = strFrom.length();
		int intPos;

		while((intPos = strSource.indexOf(strFrom)) != -1){
			strDest = strDest + strSource.substring(0,intPos);
			strDest = strDest + strTo;
			strSource = strSource.substring(intPos + intFromLen);
		}
		strDest = strDest + strSource;
		return strDest;
	}
	//高全坤，2010-3-2,功能：取oracle long型字段类型值；使用：content=(String)getLargerString(reader)；
	public String getLargerString(java.io.Reader reader)throws Exception{
		char[] content = new char[1024000];
		char[] buffer = new char[1024];
		int len = 0;
		int off = 0;
		int contentLen = 1024000;
		while (true) {
			len = reader.read(buffer);
			if (len == -1)
				break;
			if (off + len > contentLen) {
				char[] tmp = new char[contentLen + 1024000];
				System.arraycopy(content, 0, tmp, 0, off);
				content = tmp;
				contentLen = contentLen + 1024000;
			}
			System.arraycopy(buffer, 0, content, off, len);
			off = off + len;
		}
		return new String(content, 0, off);
	}//end public
	//高全坤 2009-3-6      得到一个指定月份的天数（考虑润年）
//strM:月份 strY:年份（4位） 参数都是以字符串的形式传入，返回整形的天数
	public int GetMdays(String strM,String strY){
		int i=Integer.parseInt(strM);
		int s2[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
		int y=Integer.parseInt(strY);
		if(y%4==0){
			if(y%100!=0)
				s2[2]=29;
			else if(y%100==0 && y%400==0)
				s2[2]=29;
		}
		if(i<1 || i>12)
			return 0;
		else
			return s2[i];
	}
	//高全坤 2009-02-16 功能：数字格式化函数；说明：formatsj后面的数字就是保留的小数位，适合float,double
	public float formatsj0(float sj){
		DecimalFormat df1 = new DecimalFormat("######0");
		float rsj= Float.parseFloat(df1.format(sj));
		return rsj;
	}
	public double formatsj0(double sj){
		DecimalFormat df1 = new DecimalFormat("######0");
		double rsj= Double.parseDouble(df1.format(sj));
		return rsj;
	}

	public float formatsj1(float sj){
		DecimalFormat df1 = new DecimalFormat("######0.0");
		float rsj= Float.parseFloat(df1.format(sj));
		return rsj;
	}
	public double formatsj1(double sj){
		DecimalFormat df1 = new DecimalFormat("######0.0");
		double rsj= Double.parseDouble(df1.format(sj));
		return rsj;
	}

	public float formatsj2(float sj){
		DecimalFormat df1 = new DecimalFormat("######0.0#");
		float rsj= Float.parseFloat(df1.format(sj));
		return rsj;
	}
	public double formatsj2(double sj){
		DecimalFormat df1 = new DecimalFormat("######0.0#");
		double rsj= Double.parseDouble(df1.format(sj));
		return rsj;
	}

	public float formatsj3(float sj){
		DecimalFormat df1 = new DecimalFormat("######0.0##");
		float rsj= Float.parseFloat(df1.format(sj));
		return rsj;
	}
	public double formatsj3(double sj){
		DecimalFormat df1 = new DecimalFormat("#############0.0##");
		double rsj= Double.parseDouble(df1.format(sj));
		return rsj;
	}
	public float formatsj4(float sj){
		DecimalFormat df1 = new DecimalFormat("######0.0###");
		float rsj= Float.parseFloat(df1.format(sj));
		return rsj;
	}
	public double formatsj4(double sj){
		DecimalFormat df1 = new DecimalFormat("######0.0###");
		double rsj= Double.parseDouble(df1.format(sj));
		return rsj;
	}
	public float formatsj5(float sj){
		DecimalFormat df1 = new DecimalFormat("######0.0####");
		float rsj= Float.parseFloat(df1.format(sj));
		return rsj;
	}
	public double formatsj5(double sj){
		DecimalFormat df1 = new DecimalFormat("######0.0####");
		double rsj= Double.parseDouble(df1.format(sj));
		return rsj;
	}
	//高全坤 2009-02-16 功能：数字格式化函数；说明：适合String
	public String format(float f, int i) {
		String fTemp = new String("");
		fTemp = String.valueOf((new BigDecimal(f)).setScale(i, 5));
		if (Float.parseFloat(fTemp) == 0.0F)
			fTemp = "";
		return fTemp;
	}

	public String format(double f, int i) {
		String fTemp = new String("");
		fTemp = String.valueOf((new BigDecimal(f)).setScale(i, 5));
		if (Float.parseFloat(fTemp) == 0.0F)
			fTemp = "";
		return fTemp;
	}

	//格式化数字
	public String formatsj21(double f, int i) {

		String fTemp = "";
		try{
			fTemp = String.valueOf((new BigDecimal(f)).setScale(i, 5));
			//System.out.println((new BigDecimal(f)));
			if (Float.parseFloat(fTemp) == 0.0F)
				fTemp = "";
		}catch(Exception e){

		}
		return fTemp;
	}



	//高全坤 2010-05-04 功能：汉字转拼音缩写；说明：* @param str  //要转换的汉字字符串;@return String  //拼音缩写大写字母；
	public String getPYString(String str){
		String tempStr = "";
		for(int i=0; i<str.length(); i++) {
			char c = str.charAt(i);
			if((int)c >= 33 && (int)c <=126) {//字母和符号原样保留
				tempStr += String.valueOf(c);
			}else {//累加拼音声母
				tempStr += getPYChar( String.valueOf(c) );
			}
		}
		return tempStr.toUpperCase();
	}
	//* 取单个字符的拼音声母* @param c  //要转换的单个汉字* @return String 拼音声母
	public String getPYChar(String c){
		byte[] array = new byte[2];
		array = String.valueOf(c).getBytes();
		int i = (short)(array[0] - '\0' + 256) * 256 + ((short)(array[1] - '\0' + 256));
		if ( i < 0xB0A1) return "*";
		if ( i < 0xB0C5) return "a";
		if ( i < 0xB2C1) return "b";
		if ( i < 0xB4EE) return "c";
		if ( i < 0xB6EA) return "d";
		if ( i < 0xB7A2) return "e";
		if ( i < 0xB8C1) return "f";
		if ( i < 0xB9FE) return "g";
		if ( i < 0xBBF7) return "h";
		if ( i < 0xBFA6) return "j";
		if ( i < 0xC0AC) return "k";
		if ( i < 0xC2E8) return "l";
		if ( i < 0xC4C3) return "m";
		if ( i < 0xC5B6) return "n";
		if ( i < 0xC5BE) return "o";
		if ( i < 0xC6DA) return "p";
		if ( i < 0xC8BB) return "q";
		if ( i < 0xC8F6) return "r";
		if ( i < 0xCBFA) return "s";
		if ( i < 0xCDDA) return "t";
		if ( i < 0xCEF4) return "w";
		if ( i < 0xD1B9) return "x";
		if ( i < 0xD4D1) return "y";
		if ( i < 0xD7FA) return "z";
		return "*";
	}
	//高全坤 2010-05-04 功能：判断字符串是否数字，正则表达式法；
	public static boolean isNumeric(String str){
		if(str.matches("\\d*")){
			return true;
		}else{
			return false;
		}
	}
	//高全坤 2010-05-10 返回日期d1加/减一个时间段（由AddType指定时间段类型是年还是月等等）后的日期
//参数：
//d1:原日期
//AddType:要加的时间段类型 0-年 1-月 2-日 3-小时 4-分 5-秒 6-毫秒
//val:添加的时间段长度值
//例如：Date d1=new Date(),d2;
//d2=DateAdd(d1,0,2) 	d2就是d1加上两年之后的日期
	public java.util.Date DateAdd(java.util.Date d1,int AddType,int val){
		//0-Year 1-Month 2-Day 3-Hour 4-Minute 5-second 6-millisecond
		java.util.Calendar cl=Calendar.getInstance();

		cl.setTime(d1);
		int nType;

		switch(AddType){
			case 0:
				nType=Calendar.YEAR;
				break;
			case 1:
				nType=Calendar.MONTH;
				break;
			case 2:
				nType=Calendar.DAY_OF_MONTH;
				break;
			case 3:
				nType=Calendar.HOUR;
				break;
			case 4:
				nType=Calendar.MINUTE;
				break;
			case 5:
				nType=Calendar.SECOND;
				break;
			case 6:
				nType=Calendar.MILLISECOND;
				break;
			default:
				nType=Calendar.DATE;
		}
		cl.add(nType,val);
		return cl.getTime();
	}
	//高全坤 2010-06-16/删除某个文件\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	public void delFile(String filePathAndName){
		try{
			String filePath=filePathAndName;
			filePath=filePath.toString();
			java.io.File myDelFile=new  java.io.File(filePath);
			myDelFile.delete();
		}catch(Exception e){
			e.printStackTrace();
		}

	}
	//韩北京 MD5 密码加密
	static String md5_2(String source) {
		try{
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(source.getBytes());
			byte[] digest = md5.digest();
			BigInteger code = new BigInteger(1, digest);
			return (code.toString(16)).toUpperCase();
		}catch (Exception e){
			return null;
		}
	}
	//韩北京 字符转换数字编码
	public String strToChar(String str1){
		String str1_s="";
		char[] c=str1.toCharArray();
		for(int i=0;i<c.length;i++){
			str1_s +=(int)c[i]+"-";
		}
		str1_s=str1_s.substring(0,str1_s.length()-1);
		return str1_s;
	}
	//高全坤 2010-07-02/用|分割字符串\\\\\\\\\\\
	public String wordarr(String words, int x){
		String str1="";
		if (x==1)
			str1=mid(words,words.indexOf("|")+1);
		else
			str1=left(words,words.indexOf("|"));
		return str1;
	}
	public String mid(String words,int x) {
		String str1=words.substring(x,words.length());
		return str1;
	}
	public String left(String words,int x) {
		String str1=words.substring(0,x);
		return str1;
	}
	public String right(String words,int x,int y) {
		String str1=words.substring(x,y);
		return str1;
	}


	//刘寿福
	public String getasc(String  ceshi){//字符--->ascii
		char[]dd= ceshi.toCharArray();
		String pp="";
		for(int i=0;i<dd.length;i++){
			pp=pp+(int)dd[i]+",";
		}
		// System.out.println(pp);
		return pp;
	}

	//刘寿福
	public String returnasc(String  pp){//ascII--->字符
		String[]  ddd=pp.split(",");
		char []dd=new char[ddd.length];
		for(int i=0;i<dd.length;i++){
			dd[i]=(char) Integer.parseInt(ddd[i]);
		}
		return new String(dd);
	}
	public String isdatenull(java.sql.Date dd){
		if(dd!=null){
			return dd.toString();
		}else{
			return "";
		}
	}

	//高全坤 2011-02-11\\\\\\获取两个日期间天数
	public int myTS(String date1,String date2) throws ParseException{
		int ts=0;
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		long to = df.parse(date2).getTime();
		long from = df.parse(date1).getTime();
		ts=(int) ((to - from)/(1000 * 60 * 60 * 24))+1;
		return ts;
	}
	//高全坤 2011-02-11\\\\\\获取两个月份之间的所有月份，返回一个List，若取月份数则使用List.size();即可。
	public static ArrayList<String> findMonths(String str1,String str2) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
		String str3=str1;
		String str4=str2;
		Date dBegin =sdf.parse(str3);
		Date dEnd = sdf.parse(str4);
		ArrayList<String> lDate = new ArrayList<String>();
		lDate.add(sdf.format(dBegin).substring(0, 6));

		Calendar cal = Calendar.getInstance();
		//使用给定的 Date 设置此 Calendar 的时间
		cal.setTime(dBegin);

		boolean bContinue = true;
		while (bContinue) {
			//根据日历的规则，为给定的日历字段添加或减去指定的时间量
			cal.add(Calendar.MONTH, 1);
			// 测试此日期是否在指定日期之后
			if (dEnd.after(cal.getTime())) {
				lDate.add(sdf.format(cal.getTime()).substring(0, 6));
			} else {
				break;
			}
		}
		lDate.add(sdf.format(dEnd).substring(0, 6));
		return lDate;
	}
	//中文转换为UTF-8编码
	public String GBToUTF8(String s) {
		if(s!=null&&!s.equals("")){
			StringBuffer sb = new StringBuffer();
			for (int i=0;i<s.length();i++) {
				char c = s.charAt(i);
				if (c >= 0 && c <= 255) {
					sb.append(c);
				} else {
					byte[] b;
					try {
						b = Character.toString(c).getBytes("utf-8");
					} catch (Exception ex) {
						System.out.println(ex);
						b = new byte[0];
					}
					for (int j = 0; j < b.length; j++) {
						int k = b[j];
						if (k < 0) k += 256;
						sb.append("%" + Integer.toHexString(k).
								toUpperCase());
					}
				}
			}
			return sb.toString();
		}else{
			return "";
		}
	}
	//UTF-8转换为中文编码
	public String UTF8ToGB(String s){
		if(s!=null&&!s.equals("")){
			StringBuffer sb = new StringBuffer();
			for(int i=0; i<s.length(); i++) {
				char c = s.charAt(i);
				switch (c) {
					case '+':
						sb.append(' ');
						break;
					case '%':
						try {
							sb.append((char)Integer.parseInt(
									s.substring(i+1,i+3),16));
						}
						catch (NumberFormatException e) {
							throw new IllegalArgumentException();
						}
						i += 2;
						break;
					default:
						sb.append(c);
						break;
				}
			}
			String result = sb.toString();
			try{
				byte[] inputBytes = result.getBytes("8859_1");
				result=new String(inputBytes,"UTF-8");
			}catch(Exception e) {
				e.toString();
			}
			return result;
		}else{
			return "";
		}
	}

	//wzhuo将texterea的格式转换为html格式展示，避免texterea换行时html不换行
	public String areatohtml(String pstrWord){
		pstrWord=pstrWord.replaceAll( "\n", " <br>");
		return pstrWord;
	}
	public String htmltoarea(String pstrWord){
		pstrWord=pstrWord.replaceAll( "<br>", "\n");
		return pstrWord;
	}
	//二、三级单位权限查看
//一级：采油工程研究院.酸化压裂研究室、作业工艺研究室、试油设计研究室 /院领导/钻采部
//二级：采油厂.地质研究所、工程技术研究所
//三级：采油厂.工区//钻采工程部
	public boolean isyjQx(String ejdw){
		if(ejdw.endsWith("院")||ejdw.endsWith("处")||ejdw.endsWith("部")||ejdw.endsWith("油田公司")){
			return true;
		}else{
			return false;
		}
	}

	public boolean isejQx(String sjdw){
		if(sjdw.endsWith("所")||sjdw.endsWith("机关")||sjdw.endsWith("领导")||sjdw.endsWith("队")||sjdw.startsWith("作业大队")){
			return true;
		}else{
			return false;
		}
	}
	public boolean issjQx(String sjdw){
		sjdw=sjdw.trim();
		if( sjdw.endsWith("区") || sjdw.endsWith("站") || sjdw.endsWith("零散井") || sjdw.endsWith("风险作业") ){
			return true;
		}else{
			return false;
		}
	}
	//张淼 把20121212121212转换成2012-12-12 12:12:12形式
	public StringBuffer toSJRQ(String sjrq){
		StringBuffer buf = new StringBuffer();
		buf.append(sjrq);
		buf.insert(4,"-");
		buf.insert(7,"-");
		buf.insert(10," ");
		buf.insert(13,":");
		buf.insert(16,":");
		return buf;
	}
	//张淼 把2012-12-12 12:12:12转换成20121212121212形式
	public String tosjrq(String sjrq){
		sjrq=sjrq.trim();
		String sjrq2="";
		if(sjrq != null && !"".equals(sjrq)){
			for(int i=0;i<sjrq.length();i++){
				if(sjrq.charAt(i)>=48 && sjrq.charAt(i)<=57){
					sjrq2+=sjrq.charAt(i);
				}
			}
		}
		return sjrq2;
	}
	//wz 把20121212121212转换成2012-12-12 12:12:12形式
	public String tosjrq1(String sjrq){
		sjrq=sjrq.trim();
		String sjrq2="";
		if(sjrq != null && !"".equals(sjrq)){
			sjrq2=sjrq.substring(0,4)+"-"+sjrq.substring(4,6)+"-"+sjrq.substring(6,8)+" "+sjrq.substring(8,10)+":"+sjrq.substring(10,12)+":"+sjrq.substring(12,14);
		}
		return sjrq2;
	}
	public String tosjrq2(String sjrq){
		sjrq=sjrq.trim();
		String sjrq2="";
		if(sjrq != null && !"".equals(sjrq)){
			sjrq2=sjrq.substring(0,4)+"-"+sjrq.substring(5,7)+"-"+sjrq.substring(8,10)+" "+sjrq.substring(12,13)+":"+sjrq.substring(15,16)+":"+sjrq.substring(18,19);
		}
		return sjrq2;
	}
	public String tosjrq3(String sjrq){
		sjrq=sjrq.trim();
		String sjrq2="";
		if(sjrq != null && !"".equals(sjrq)){
			sjrq2=sjrq.substring(0,4)+"-"+sjrq.substring(5,7)+"-"+sjrq.substring(8,10)+" "+sjrq.substring(11,13)+":"+sjrq.substring(14,15)+":"+sjrq.substring(17,18);
		}
		return sjrq2;
	}
	//2013-07-19 生成10个随机字符，类型为：大小写英文字符和10个阿拉伯数字。
	public String getTenRandom(){
		String tenRandom="";
		char[] str={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};
		java.util.Random random=new java.util.Random();
		for(int i=0;i<10;i++){
			int j=random.nextInt(62);
			tenRandom+=str[j];
		}
		return tenRandom;
	}
	//wzhuo 2012-02-13//用于处理单元格
	public String cellisnull(String str1){
		//if(!IsNull(str1)){
		if(str1.length()>0){
			if(str1.substring(0,1).equals(".")) str1="0"+str1;
		}
		//}
		return (str1);

	}

	//黄光达 2013/9/26 指数法预测产量变化
	public  double[] zhishu(double[] pro2,int N)
	{

		int length2=pro2.length;
		double max10=0;
		int m=0;   //记录max10的index
		for(int i=0;i<10;i++)
		{
			if(pro2[i]>max10)
			{
				max10=pro2[i];
				m=i;
			}
		}
		int length3=length2-m;
		double pro3[]=new double[length3];
		for(int i=0;i<length2-m;i++)
		{
			pro3[i]=pro2[i+m];
		}





		int len=length3/N;
		double[] pro=new double[len];
		double sum=0;
		for(int i=0;i<len;i++)
		{
			for(int j=i*N;j<len*N;j++)
			{
				sum+=pro2[j];
				if((j+1)%N==0)
				{
					pro[i]=sum/N;
					//System.out.println(pro[i]);
					sum=0;
					break;
				}
			}

		}

		double[] time=new double[len];
		for(int i=0;i<len;i++)
		{
			time[i]=i;
		}
		double[] lnpro=new double[len];
		for(int i=0;i<len;i++)
		{
			lnpro[i]=Math.log(pro[i]);
		}
		double xx=0;
		double y=0;
		double x=0;
		double xy=0;
		for(int i=0;i<len;i++)
		{
			xx+=time[i]*time[i];
			y+=lnpro[i];
			x+=time[i];
			xy+=lnpro[i]*time[i];
		}
		double[] aaa=new double[2];
		aaa[0]=(xx*y-x*xy)/(len*xx-x*x);
		aaa[1]=(len*xy-x*y)/(len*xx-x*x);

		double[] params=new double[3];
		params[0]=Math.exp(aaa[0]);      //qr
		params[1]=-aaa[1];               //dr
		params[2]=len;
		return params;

	}

	//黄光达 2013/9/26 调和法预测产量变化
	public  double[] tiaohe(double[] pro2,int N)
	{
		int length2=pro2.length;
		double max10=0;
		int m=0;   //记录max10的index
		for(int i=0;i<10;i++)
		{
			if(pro2[i]>max10)
			{
				max10=pro2[i];
				m=i;
			}
		}
		int length3=length2-m;
		double pro3[]=new double[length3];
		for(int i=0;i<length2-m;i++)
		{
			pro3[i]=pro2[i+m];
		}


		int len=length3/N;
		double[] pro=new double[len];
		double sum=0;
		for(int i=0;i<len;i++)
		{
			for(int j=i*N;j<len*N;j++)
			{
				sum+=pro2[j];
				if((j+1)%N==0)
				{
					pro[i]=sum/N;
					//System.out.println(pro[i]);
					sum=0;
					break;
				}
			}

		}

		double[] time=new double[len];
		for(int i=0;i<len;i++)
		{
			time[i]=i;
		}

		double[] x1=new double[len];
		for(int i=0;i<len;i++)
		{
			x1[i]=pro[i]*time[i];
		}
		double xx=0;
		double y=0;
		double x=0;
		double xy=0;
		for(int i=0;i<len;i++)
		{
			xx+=x1[i]*x1[i];
			y+=pro[i];
			x+=x1[i];
			xy+=pro[i]*x1[i];
		}
		double[] aaa=new double[2];
		aaa[0]=(xx*y-x*xy)/(len*xx-x*x);
		aaa[1]=(len*xy-x*y)/(len*xx-x*x);

		double[] params=new double[3];
		params[0]=aaa[0];                //qr
		params[1]=-aaa[1];               //dr
		params[2]=len;
		return params;
	}
	//黄光达 2013/9/26 双曲法预测产量变化
	public  double[] shuangqu(double[] pro2, int N)
	{

		int length2=pro2.length;
		double max10=0;
		int m=0;   //记录max10的index
		for(int i=0;i<10;i++)
		{
			if(pro2[i]>max10)
			{
				max10=pro2[i];
				m=i;
			}
		}
		int length3=length2-m;
		double pro3[]=new double[length3];
		for(int i=0;i<length2-m;i++)
		{
			pro3[i]=pro2[i+m];
		}


		int len=length3/N;
		double[] pro=new double[len];
		double sum2=0;
		for(int i=0;i<len;i++)
		{
			for(int j=i*N;j<len*N;j++)
			{
				sum2+=pro2[j];
				if((j+1)%N==0)
				{
					pro[i]=sum2/N;
					//System.out.println(pro[i]);
					sum2=0;
					break;
				}
			}

		}

		double[] time=new double[len];
		for(int i=0;i<len;i++)
		{
			time[i]=i;
		}


		double sumtemp = 0;
		double[] sum = new double[len];
		for (int i = 0; i < len; i++) {

			sum[i] = sumtemp;
			sumtemp = sumtemp + pro[i];
		}

		double[] x2=new double[len];
		for(int i=0;i<len;i++)
		{
			x2[i]=pro[i]*time[i];
		}

		double a1=len;
		double b1=0;
		double c1=0;
		double d1=0;
		double d2=0;
		double d3=0;
		double a2=0;
		double b2=0;
		double c2=0;
		double a3=0;
		double b3=0;
		double c3=0;
		for (int i=0;i<len;i++)
		{

			b1 =b1+pro[i];
			c1 =c1+x2[i];
			b2 =b2+pro[i]*pro[i];
			c2 =c2+pro[i]*x2[i];
			c3 =c3+x2[i]*x2[i];
			d1 =d1+sum[i];
			d2 =d2+sum[i]*pro[i];
			d3 =d3+sum[i]*x2[i];
		}
		a2=b1;
		b3=c2;
		a3=c1;
		double[] params=new double[3];
		params[0]=((d1*c2-d2*c1)*(b2*c3-b3*c2)-(d2*c3-d3*c2)*(b1*c2-b2*c1))/((a1*c2-a2*c1)*(b2*c3-b3*c2)-(a2*c3-a3*c2)*(b1*c2-b2*c1));
		params[1]=((d1*c2-d2*c1)*(a2*c3-a3*c2)-(d2*c3-d3*c2)*(a1*c2-a2*c1))/((a2*c3-a3*c2)*(b1*c2-b2*c1)-(a1*c2-a2*c1)*(b2*c3-b3*c2));
		params[2]=(d1-a1*params[0]-b1*params[1])/c1;
		double[] BB=new double[4];
		BB[0]=-params[0]/params[1];         //Qi
		BB[1]=(params[2]-1)/params[1];      //Di
		BB[2]=(params[2]-1)/params[2];      //N
		BB[3]=len;
		return BB;

	}

	public  double[] wengshi(double[] pro2,int N)
	{
		int length2=pro2.length;
		double max10=0;
		int m=0;   //记录max10的index
		for(int i=0;i<10;i++)
		{
			if(pro2[i]>max10)
			{
				max10=pro2[i];
				m=i;
			}
		}
		int length3=length2-m;
		double pro3[]=new double[length3];
		for(int i=0;i<length2-m;i++)
		{
			pro3[i]=pro2[i+m];
		}


		int len=length3/N;
		double[] pro=new double[len];
		double sum=0;
		for(int i=0;i<len;i++)
		{
			for(int j=i*N;j<len*N;j++)
			{
				sum+=pro2[j];
				if((j+1)%N==0)
				{
					pro[i]=sum/N;
					//System.out.println(pro[i]);
					sum=0;
					break;
				}
			}

		}

		double[] time=new double[len];
		for(int i=0;i<len;i++)
		{
			time[i]=i+1;
		}

		double[] lnQ = new double[len];
		for (int i = 0; i < len; i++) {

			lnQ[i] = Math.log(pro[i]);

		}

		double[] x2=new double[len];
		for(int i=0;i<len;i++)
		{
			x2[i]=Math.log(time[i]);
		}

		double a1=len;
		double b1=0;
		double c1=0;
		double d1=0;
		double d2=0;
		double d3=0;
		double a2=0;
		double b2=0;
		double c2=0;
		double a3=0;
		double b3=0;
		double c3=0;
		for (int i=0;i<len;i++)
		{

			b1 =b1+time[i];
			c1 =c1+x2[i];
			b2 =b2+time[i]*time[i];
			c2 =c2+time[i]*x2[i];
			c3 =c3+x2[i]*x2[i];
			d1 =d1+lnQ[i];
			d2 =d2+lnQ[i]*time[i];
			d3 =d3+lnQ[i]*x2[i];
		}
		a2=b1;
		b3=c2;
		a3=c1;
		double[] params=new double[3];
		params[0]=((d1*c2-d2*c1)*(b2*c3-b3*c2)-(d2*c3-d3*c2)*(b1*c2-b2*c1))/((a1*c2-a2*c1)*(b2*c3-b3*c2)-(a2*c3-a3*c2)*(b1*c2-b2*c1));
		params[1]=((d1*c2-d2*c1)*(a2*c3-a3*c2)-(d2*c3-d3*c2)*(a1*c2-a2*c1))/((a2*c3-a3*c2)*(b1*c2-b2*c1)-(a1*c2-a2*c1)*(b2*c3-b3*c2));
		params[2]=(d1-a1*params[0]-b1*params[1])/c1;
		double[] BB=new double[4];
		BB[0]= Math.exp(params[0]);      //a
		BB[1]=params[2];     //b
		BB[2]=-params[1] ;    //c
		BB[3]=len ;    //c
		return BB;

	}


%> 
